//
//  HLPalcehodarTextView.swift
//  HLwWeibo
//
//  Created by hqhxu on 16/3/7.
//  Copyright © 2016年 hqhxu. All rights reserved.
//

import UIKit

import SnapKit

class HLPalcehodarTextView: UITextView {

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    var placehodar:String? {
        didSet {
            placehodarLabel.text = placehodar
            placehodarLabel.sizeToFit()
        }
    }
    
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        
        self.font = UIFont.systemFontOfSize(18)
        self.alwaysBounceVertical = true
        
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "placehodarLabelHidden", name: UITextViewTextDidChangeNotification, object: self)
    }
    

    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }

    func placehodarLabelHidden() {
        placehodarLabel.hidden = self.hasText()
    }
    
    
    private lazy var placehodarLabel:UILabel = {
        let label = UILabel()
        
        label.textColor = UIColor.lightGrayColor()
        self.addSubview(label)
        label.font = self.font
        
        label.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(5)
            make.top.equalTo(self).offset(8)
        }
        return label
    }()
}

//extension HLPalcehodarTextView :UITextViewDelegate{
//    
//    func textViewDidChange(textView: UITextView) {
//        
//        placehodarLabel.hidden = hasText()
//    }
//}